#pragma once
#include <windows.h>

#include "..\math\matrix.h"
#include "..\math\vector.h"
#include "..\common\def.h"
#include "..\common\string.h"
#include "..\common\arraylist.hpp"
#include "..\render\d3d_mesh.h"
#include "actor.h"
#include "characteractor.h"
#include "Physics\Dynamics\World\hkpWorld.h"
#include "Physics\Collide\Shape\hkpShape.h"
#ifdef _DEBUG
#include "Common\Visualize\hkVisualDebugger.h"
#include "Physics\Utilities\VisualDebugger\hkpPhysicsContext.h"
#endif

#define VISUAL_DEBUGGER 
class CObject;


hkTransform TohkTransform(const Matrix4f& m);
hkTransform ToEEhkTransform(float* pMat);
Matrix4f ToMatrix4f(const hkTransform& m);
Vector3f ToVector3f(const hkVector4& v);
hkVector4 TohkVector4(const Vector3f& v);

class EE_EXPORT CPhysics
{
	friend class CActor;
private:

	hkpWorld* mp_World;
	ArrayList<CActor*> m_Actors;
	ArrayList<hkpShape*> m_Shapes;

	static void OnError(const char* pMessage, void* pErrorObject);

#ifdef _DEBUG
	hkVisualDebugger *mp_VisualDebug;
	hkpPhysicsContext *pPhysicsContext;
#endif

public:


	CPhysics(); 
	virtual~ CPhysics();

	enum PhysicsShape
	{
		SPHERE = 0,
		BOX = 1,
		CONVEX_MESH = 2
	};

	hkpWorld* GetScene();
	void Update(const float dt); 

	void LockSimulation(void); 
	void UnlockSimulation(void); 

	HRESULT Release(void); 
	HRESULT Initailize(void); 
	HRESULT CreateWorld(const string& filename, void** pHandle); 
	HRESULT CreateActor(const string& filename, CActor** pOut, CActor::ActorData actorData = CActor::ActorData(), CObject *pParent = NULL); 
	HRESULT CreateFieldActor(const string& filename, CActor** pOut, const Matrix4f& initalTransform, CObject *pParent = NULL); 
	HRESULT CreateCharacterActor(const string& filename, CCharacterActor** pOut, CActor::ActorData actorData = CActor::ActorData(), CObject *pParent = NULL); 
	HRESULT ReleaseActor(CActor* pActor); 

	HRESULT RegisterCollisionEvent(CObject* pObjectA, CObject* pObjectB, void(*pFunc) (void)); 

}; 
